// index.js
// 获取应用实例
const app = getApp()

Page({
  /**
   * 页面的初始数据
   */
  data: {
    startPosition: null,
    endPosition: null,
    type:'recommend',
    opacityDate: .2,
    animationionDate: {},
    inputRes: [],
    inputDisplay: "none",
    headBanner: [
      {"imgUrl": "https://pic-1307871431.cos.ap-chengdu.myqcloud.com//imageshead1.jfif"},
      {"imgUrl": "https://pic-1307871431.cos.ap-chengdu.myqcloud.com//imageshead2.jfif"},
      {"imgUrl": "https://pic-1307871431.cos.ap-chengdu.myqcloud.com//imageshead3.jpeg"},
      {"imgUrl": "https://pic-1307871431.cos.ap-chengdu.myqcloud.com//imageshead4.jpeg"}
    ],
    navList: [
      {imgUrl: 'https://pic-1307871431.cos.ap-chengdu.myqcloud.com//imagesnav5.png', name: '门票' , tab: 'recommend'},
      {imgUrl: 'https://pic-1307871431.cos.ap-chengdu.myqcloud.com//imagesnav3.png', name: '跟团游' , tab: 'recommend'},
      {imgUrl: 'https://pic-1307871431.cos.ap-chengdu.myqcloud.com//images酒店.png', name: '酒店' , tab: 'hotel'},
      {imgUrl: 'https://pic-1307871431.cos.ap-chengdu.myqcloud.com//imagesnav2.png', name: '路线' , tab: 'navigation'},
      {imgUrl: 'https://pic-1307871431.cos.ap-chengdu.myqcloud.com//imagesnav1.png', name: '自由游' , tab: 'recommend'},
    ],
    top_swiper: [
      {}
    ],
    bannerSwiperList: [
      {"Url": 'https://pic-1307871431.cos.ap-chengdu.myqcloud.com//imagesfirst.jfif', id: '1',name: "景点排行"},
      {"Url": 'https://pic-1307871431.cos.ap-chengdu.myqcloud.com//imagessecond.jfif', id: '2',name: "酒店排行"}
    ],
    content_nav: [
      {name: '景点', tab: 'scenery'},
      {name: '酒店', tab: 'hotel'},
      {name: '推荐', tab: 'recommend'},
      {name: '导航', tab: 'navigation'},
      {name: '分享', tab: 'share'}
    ],
    recommendSceneryList: [
    ],
    recommendHotelList: [
      {imgUrl: 'https://pic-1307871431.cos.ap-chengdu.myqcloud.com/img/recommend1.jpg', title: "张本友", itr:'新疆天山天池风景名胜区位于新疆半山腰，是中实打实的静安寺国家级风', "id": "1"},
      {imgUrl: 'https://pic-1307871431.cos.ap-chengdu.myqcloud.com/img/recommend1.jpg', title: "张本友", itr:'新疆天山天池风景名胜区位于新疆半山腰，是中实打实的静安寺国家级风', "id": "2"},
      {imgUrl: 'https://pic-1307871431.cos.ap-chengdu.myqcloud.com/img/recommend1.jpg', title: "张本友", itr:'新疆天山天池风景名胜区位于新疆半山腰，是中实打实的静安寺国家级风', "id": "3"},
      {imgUrl: 'https://pic-1307871431.cos.ap-chengdu.myqcloud.com/img/recommend1.jpg', title: "张本友", itr:'新疆天山天池风景名胜区位于新疆半山腰，是中实打实的静安寺国家级风', "id": "4"},
    ],
    shareData : []
  },
  changeTodetail(e) {
    wx.redirectTo({
      url: '../contentpage/contentpage?'+'id='+e.currentTarget.dataset.id,
    })
  },
  bindtapRecommend(e){
    wx.reLaunch({
      url: '../scenerypage/scenerypage?'+'id='+e.currentTarget.dataset.id,
    })
  },
  changeType(e) {
    const type = e.currentTarget.dataset.type;
    this.setData({ type });

  },
  onPageScroll: function(res) {
    var animation = wx.createAnimation({
      delay: 20,
      timingFunction: 'linear'
    })
    if(res.scrollTop > 250)
    {
      animation.opacity(1).step();
      this.setData({
        animationionDate: animation.export()
      })
    }
    if(res.scrollTop < 250 ){
      animation.opacity(.2).step();
      this.setData({
        animationionDate: animation.export()
      })
    }
  },
  changeTop: function() {
    this.setData({opacityDate: 1})
  },
  touchstart: function(e) {
    this.setData({
      startPosition:e.changedTouches[0].pageX,
    })
  },
  touchend: function(e) {
    this.setData({
      endPosition:e.changedTouches[0].pageX,
    })
    if((this.data.endPosition - this.data.startPosition ==0)&& e.currentTarget.id == 1)
    {
      wx.redirectTo({
        url: '../top/top',
      })
    }
    if((this.data.endPosition - this.data.startPosition ==0)&& e.currentTarget.id == 2)
    {
      wx.redirectTo({
        url: '../hotel/hotel',
      })
    }
  },
  onLoad() {
    wx.request({
      url: 'https://api.chaofan.xyz/v2/scenery/4', //仅为示例，并非真实的接口地址 
      header: {
        'content-type': 'application/json' 
      },
      success:res=> {
        const recommendSceneryList = res.data.data;
        this.setData({recommendSceneryList})
      }
    })
    wx.request({
      url: 'https://api.chaofan.xyz/v2/hotel/4', //仅为示例，并非真实的接口地址 
      header: {
        'content-type': 'application/json' 
      },
      success:res=> {
        const recommendHotelList = res.data.data;
        this.setData({recommendHotelList})
      }
    })
    wx.request({
      url: 'https://api.chaofan.xyz/v2/recommendShareList', //仅为示例，并非真实的接口地址 
      header: {
        'content-type': 'application/json' 
      },
      success:res=> {
        const shareData = res.data.data;
        this.setData({shareData})

        console.log(this.data.shareData)
      }
    })
    
  },
  inputbat: function(e) {
    var val = e.detail.value
    if(val == 0) {
      this.setData({inputDisplay: "none"})
    }
    else {
      this.setData({inputDisplay: "block"})
      wx.request({
        url: 'https://www.baidu.com/sugrec?pre=1&p=3&ie=utf-8&json=1&prod=pc&from=pc_web',
        dataType:"jsonp",
        jsonp: 'cb',
        data:{"wd" : val },
        success:res=> {
          var b = (JSON.parse(res.data))
          var c = b.g
          const inputRes = c;
          this.setData({inputRes})
        }
      })
    } 
  },
  changeTypes: function(e) {
    const type = e.currentTarget.dataset.type;
    this.setData({ type });
  }
})